using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region DicType

	/// <summary>
	/// DicType object for NHibernate mapped table 'DicType'.
	/// </summary>
	[Serializable]
	public class DicType : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _dicTypeKey;
		protected string _description;
		protected bool _isSys;
		protected string _cODOrOCO;
		protected IList _dicItems;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public DicType() { }

		public DicType( string dicTypeKey, string description, bool isSys)
		{
			this._dicTypeKey = dicTypeKey;
			this._description = description;
			this._isSys = isSys;
			this._cODOrOCO = "COD";
		}

		public DicType( string dicTypeKey, string description, bool isSys, string cODOrOCO )
		{
			this._dicTypeKey = dicTypeKey;
			this._description = description;
			this._isSys = isSys;
			this._cODOrOCO = cODOrOCO;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string DicTypeKey
		{
			get { return _dicTypeKey; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for DicTypeKey", value, value.ToString());
				_dicTypeKey = value;
			}
		}

		public string Description
		{
			get { return _description; }
			set
			{
				if ( value != null && value.Length > 250)
					throw new ArgumentOutOfRangeException("Invalid value for Description", value, value.ToString());
				_description = value;
			}
		}

		public bool IsSys
		{
			get { return _isSys; }
			set { _isSys = value; }
		}

		public string CODOrOCO
		{
			get { return _cODOrOCO; }
			set
			{
				if ( value != null && value.Length > 5)
					throw new ArgumentOutOfRangeException("Invalid value for CODOrOCO", value, value.ToString());
				_cODOrOCO = value;
			}
		}

		public IList DicItems
		{
			get
			{
				if (_dicItems==null)
				{
					_dicItems = new ArrayList();
				}
				return _dicItems;
			}
			set { _dicItems = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is DicType))
				throw new InvalidCastException("This object is not of type DicType");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((DicType)obj).Id);
					break;
				case "DicTypeKey":
						relativeValue = ( this.DicTypeKey != null ) ? this.DicTypeKey.CompareTo(((DicType)obj).DicTypeKey) : -1;
					break;
				case "Description":
						relativeValue = ( this.Description != null ) ? this.Description.CompareTo(((DicType)obj).Description) : -1;
					break;
				case "IsSys":
						relativeValue = ( this.IsSys != Convert.ToBoolean( null) ) ? this.IsSys.CompareTo(((DicType)obj).IsSys) : -1;				
					break;
				case "CODOrOCO":
						relativeValue = ( this.CODOrOCO != null ) ? this.CODOrOCO.CompareTo(((DicType)obj).CODOrOCO) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (DicType.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
